let express =require('express')
let multer =require('multer')
let path =require("path")
let {v4} =require("uuid")
let apiAddr=require("../config/PublicPath")


let uploadImgFileApp=express()

//设置文件上传
let storage = multer.diskStorage({
    destination: function (req, file, cb) {
        if (file.mimetype.includes('image')) {
            cb(null, path.join(__dirname, '../storage/images'))
        }
    },
    filename: function (req, file, cb) {
        cb(null, v4() + file.originalname)
    }
})

let uploadParams = multer({
    storage
})
let uploadConfig=uploadParams.fields([
        {
            name:"blogIllustrations",
            maxCount:8
        }
])


uploadImgFileApp.post("/",uploadConfig,(req,res)=>{

    // console.log(req.files.blogIllustrations)
    let resData=[]
    for (let i=0,len=req.files.blogIllustrations.length;i<len;i++){
        resData.push(`${apiAddr.hostAddr}${apiAddr.getImgApiAddr}/${req.files.blogIllustrations[i].filename}`)
    }
    res.send({
        status:"200",
        data:{
            imgList:resData
        }
    })
})
module.exports = {uploadImgFileApp}